import 'package:flutter/material.dart';

import 'grid_model.dart';

class GridItemWidget extends StatefulWidget {
  GridModel grid;
  GridItemWidget(this.grid);

  @override
  _GridItemWidgetState createState() => _GridItemWidgetState();
}

class _GridItemWidgetState extends State<GridItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.blueGrey,
      ),
      child: Stack(
        alignment: Alignment.center,
        children: [
          buildGridItem(),
        ],
      ),
    );
  }

  Widget buildGridItem() {
    Color color = Colors.grey;
    if (widget.grid.selected) {
      color = Colors.green;
    }
    return GestureDetector(
      onTap: () {
        widget.grid.selected = !widget.grid.selected;
        setState(() {});
      },
      child: Container(
        alignment: Alignment.center,
        width: 60,
        height: 30,
        decoration: BoxDecoration(
          color: color,
          borderRadius: BorderRadius.all(
            Radius.circular(30),
          ),
        ),
        child: Text(
          "${widget.grid.title}",
          style: TextStyle(color: Colors.white, fontSize: 16),
          textAlign: TextAlign.center,
        ),
      ),
    );
  }
}
